home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 4 / MacAddict_004_1996_12.iso / Essentials / Fetch 3.0.1 / Fetch Help / Fetch Help.rsrc / FHLP_404_ Scripting < prev    next >
Text File  |  1996-03-05  |  7KB  |  82 lines

  1. Scripting
  2.  
  3. Fetch 3.0 supports a number of Apple Events.  This makes it possible to automate Fetch’s operations with a scripting tool such as AppleScript or UserLand Frontier.  It also makes it possible for other programs to use Fetch as a “helper” application for resolving FTP Uniform Resource Locators (URLs).  This help topic describes Fetch’s support for the URL, Anarchie, and Fetch Apple Event Suites.  In addition, Fetch supports Apple Event recording.  The easiest way to find out how to script an operation is to turn on recording in your script editor, perform the operation manually, and then examine the script that has been recorded.  Finally, Fetch supports Frontier Menu Sharing, which makes it possible for UserLand Frontier to add scripts to Fetch’s menu bar.
  4.  
  5. URL Suite
  6.  
  7. Fetch supports the geturl (GURL) event from the URL Apple Event Suite, designed by John Norstad of Northwestern University and a group of Internet software authors.  In AppleScript the event is specified as follows:
  8.  
  9. tell application "Fetch 3.0"
  10.     geturl "ftp://ftp.dartmouth.edu/"
  11. end tell
  12.  
  13. The geturl event is used by the Internet Config system and other applications to pass URLs to other applications for resolution.  So e-mail programs, newsreaders, and even web browsers can pass FTP URLs to Fetch using geturl.
  14.  
  15. Anarchie Suite
  16.  
  17. Peter N Lewis’s Anarchie was the first Macintosh FTP client to support scripting via Apple Events.  Fetch 3.0 supports most of the Anarchie suite of events, to make it easier to re-use scripts written for Anarchie (and because it is a straight-forward and functional collection of events).  Descriptions of the supported events follow:
  18.  
  19. To download a file: fetch alias "My hard disk:my folder:cool file" host "ftp.domain.com" user "fred" password "secret" path "remotedir/cool.file.hqx"
  20.  
  21. To upload a file: store alias "My hard disk:my folder:file to upload" host "ftp.domain.com" user "fred" password "secret" path "uploaddir/new.file"
  22.  
  23. To delete a file or directory: remove host "ftp.domain.com" user "fred" password "secret" path "remotedir/bad.file"
  24.  
  25. To view a file list: list host "ftp.domain.com" user "fred" password "secret" path "remotedir"
  26.  
  27. To create a directory:  mkdir host "ftp.domain.com" user "fred" password "secret" path "remotedir/newdir"
  28.  
  29. To rename a file or directory: rename host "ftp.domain.com" user "fred" password "secret" path "remotedir/old.name" newname "new.name"
  30.  
  31. To send a raw FTP command: rename host "ftp.domain.com" user "fred" password "secret" command "SITE A LIST"
  32.  
  33. To search for a file name: index host "ftp.domain.com" user "fred" password "secret" path "remotedir/name.to.find"
  34.  
  35. The user and password parameters can be omitted if you are using anonymous FTP.  Also, the host, user, password, and path parameters can be replaced by a single url parameter; for example:
  36.  
  37. fetch alias "My hard disk:my folder:cool file" url "ftp://fred:secret@ftp.domain.com/remotedir/cool.file.hqx"
  38.  
  39. Fetch Suite
  40.  
  41. Fetch’s Apple Event suite follows the Apple Event Object Model, which is the “organizing principle” behind AppleScript and Apple’s scripting strategy.  The object model can be thought of as a language where Apple Events are verbs and Apple Event Objects are nouns.  The goal of this language is to be “small” but still expressive.  So the number of “verbs,” or events, has been kept small, but these verbs are supposed to be generic enough to work with many nouns.  And the nouns (i.e. objects), while many in number, are all referred to in the same way.  An object can be anything in an application: a window, a paragraph of text, a bookmark, anything that the user might want to manipulate.  Under the object model you refer to an object by first referring to the object that it is contained in.  So you talk about “bookmark 3 of bookmark list window 1,” or “remote file 'README' of transfer window 'ftp.dartmouth.edu'.”  The “top-level” container is the application itself.  So objects are said to be “elements” of other objects, and each object class defines what kind of elements it can contain.
  42.  
  43. To make this more specific, Fetch supports the following object classes:
  44.  
  45. • the application object, which can contain each of the following kinds of objects:
  46.     • window objects
  47.     • transfer window objects, which can contain:
  48.         • remote item objects
  49.         • remote file objects
  50.         • remote directory objects
  51.     • bookmark list window objects, which can contain:
  52.         • bookmark objects
  53.     • the shortcut window object, which can contain:
  54.         • bookmark objects
  55.     • text window objects
  56.     • the help window object
  57.     • the transcript window object
  58.     • url objects
  59.  
  60. Objects also have properties.  For example, the application object has all the preferences settings as properties, so you can refer to its download folder or default binary file type.
  61.  
  62. Apple event objects are manipulated with events.  The standard “Core” suite of events includes close, count, delete, duplicate, exists, get, make, move, open, quit, save, and set.  To this list Fetch adds download, view, view file list, put into, and send to.  Here are examples of these events, used with a variety of Fetch Apple Event objects:
  63.  
  64.     close text window "ftp.dartmouth.edu messages"
  65.     set bcount to count bookmark list window "Fetch Shortcuts" each bookmark
  66.     delete remote file "a.out" of transfer window "csvax.polytech.edu"
  67.     duplicate remote file "cool.gif" to beginning of alias "Hobbes:Desktop Folder:"
  68.     set fexists to exists bookmark "cool site" of bookmark list window "Fetch Shortcuts"
  69.     get use internet config
  70.     make new transfer window at beginning with properties {hostname:"ftp.dartmouth.edu", initial directory:"/pub"}
  71.     move bookmark 1 of bookmark list window "Fetch Shortcuts" to beginning of bookmark list window "Best Bookmarks"
  72.     open parent directory of transfer window 1
  73.     quit
  74.     save text window "ftp.dartmouth.edu messages" in alias "Hobbes:server messages"
  75.     set transfer mode of transfer window 1 to Binary
  76.     download url "ftp://ftp.dartmouth.edu/pub/mac/README"
  77.     view remote file "README" of transfer window 1
  78.     view file list transfer window "ftp.dartmouth.edu"
  79.     put into transfer window "ftp.dartmouth.edu" item alias "Hobbes:Desktop Folder:Picture 3" binary format MacBinaryII
  80.     send to url "ftp://ftp.dartmouth.edu/" ftp command "LIST -lR"
  81.  
  82. One of the best ways to get a feel for scripting Fetch is to run your script editor, turn on recording, and then go mess around in Fetch.  Most user actions will be recorded as script statements.  It is also useful to examine Fetch’s Apple Event dictionary, since it provides a complete list of the supported object classes, properties, and events.